package com.hfy.music.mapper;

import org.apache.ibatis.annotations.*;

/**
 * @ author 韩
 * time: 2024/5/24 3:35
 */

@Mapper
public interface LikeMapper {

    @Select("SELECT id from `music_like` WHERE biz = #{biz} AND account = #{account} AND biz_id = #{bizId}")
    Integer selectLike(@Param("biz") Integer biz,@Param("account") Long account,@Param("bizId") Integer bizId);


    @Insert("INSERT INTO `music_like` (biz,account, biz_id) VALUES (#{biz},#{account},#{bizId})")
    void like(@Param("biz") Integer biz,@Param("account") Long account,@Param("bizId") Integer bizId);

    @Insert("DELETE FROM `music_like` WHERE biz = #{biz} AND account = #{account} AND biz_id = #{bizId}")
    void unlike(@Param("biz") Integer biz,@Param("account") Long account,@Param("bizId") Integer bizId);

    @Update("UPDATE `like_count` SET like_count = like_count + 1 WHERE biz=#{biz} AND biz_id=#{bizId}")
    void likeIncreaseOne(@Param("biz") Integer biz,@Param("bizId") Integer bizId);

    @Update("UPDATE `like_count` SET unlike_count = unlike_count + 1 WHERE biz=#{biz} AND biz_id=#{bizId}")
    void likeDecreaseOne(@Param("biz") Integer biz,@Param("bizId") Integer bizId);

    @Select("SELECT id FROM `like_count` WHERE biz=#{biz} AND biz_id=#{bizId}")
    Integer selectLikeCount(@Param("biz") Integer biz,@Param("bizId") Integer bizId);

    @Insert("INSERT INTO `like_count` (`biz`, `biz_id`,`like_count`) VALUES (#{biz}, #{bizId}, 1)")
    void insertLikeCount(@Param("biz") Integer biz,@Param("bizId") Integer bizId);

    @Select("SELECT id FROM `music_like` WHERE biz_id=#{commentId} AND biz=#{biz} AND account=#{account}")
    Integer queryIsLikedByAccount(@Param("commentId") Integer commentId,@Param("biz") Integer biz,@Param("account") Long account);

}
